-
Notifications
You must be signed in to change notification settings - Fork 44
feat(controller): Refactor reconcile loop and add unit tests #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Hi @ballista01. Thanks for your PR. I'm waiting for a etcd-io member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
baf8e00 to
59d969f
Compare
|
/ok-to-test |
dffb919 to
fa7f810
Compare
fa7f810 to
9250067
Compare
- split the monolithic Reconcile into fetch/sync/health/cluster phases backed by a shared reconcileState - ensure TLS setup, STS ownership checks, and primitive bootstrapping are driven through dedicated helpers - refresh controller unit tests to exercise the new helpers and drop obsolete scaffolding Signed-off-by: Wenxue Zhao <[email protected]>
9250067 to
b43d579
Compare
|
I was reading the code. But the changes look a little bit lengthy. Do you think that it would be possible to break down this pull request? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The refactoring makes sense to me. Just raised several minor comments.
Thanks.
cc @ivanvc @ArkaSaha30 @abdurrehman107 @hakman @frederiko PTAL when you get free cycle, thx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pull request, @ballista01. I left a couple of comments.
I also noticed that you removed some comments from lengthy functions. I think it makes sense to comment these functions, as it is easy to get lost with all the conditions they have. Thanks again :)
…n tests Signed-off-by: Wenxue Zhao <[email protected]>
|
The change for internal/controller/etcdcluster_controller.go looks clean and better. Thanks. (But do not get much time to look into the test case.) Let's target to merge this PR before our next WG meeting. |
|
@ivanvc any further comments on this PR? |
No, I just reviewed again, and if you're ok with this PR, we can merge it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks, @ballista01.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks for the great work!
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ahrtr, ballista01, ivanvc The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Summary
EtcdClusterReconciler.Reconcileinto focused phases to reduce cyclomatic complexity and make behavior easier to reason about.reconcileStatecontainer so data gathered in earlier phases can be reused without repeated lookups.Controller changes (
internal/controller/etcdcluster_controller.go)Split the main reconcile loop into:
fetchAndValidateStatebootstrapStatefulSetperformHealthChecksreconcileClusterStateEach returns early with a
ctrl.Resultwhen it needs a requeue or encounters an error.Introduced
reconcileState(cluster, StatefulSet, member list, member health) to pass context between phases.fetchAndValidateState:bootstrapStatefulSet:ctrl.Result.IsZero()to decide whether to continue.performHealthChecksandreconcileClusterState:memberHealth.Tests (
internal/controller/etcdcluster_controller_test.go)Replaced the previous integration-style test with table-driven unit tests using controller-runtime’s fake client.
Added
TestFetchAndValidateStateandTestBootstrapStatefulSet, switching to require for hard preconditions and asserting on StatefulSet/Service/ConfigMap outcomes.Expanded coverage for bootstrap scenarios:
Verified cluster state remains untouched when nothing changes.